<template>
  <!-- 已签单 -->
  <div >
    <div style="display: flex; align-items: center;margin: 0 20px;font-size: 14px;">
      <div>终版合同：{{ finalfile.fileName }}</div>
      <div style="margin-left: 20px;">
        <FileDownloader
          :fileUrl="finalfile.filePath"
          :fileName="finalfile.fileName"
        />
      </div>
    </div>
    <div style="margin: 0 20px">
      <el-button v-if="operationList.includes('order:splitOrder')" @click="splitOrderClick">去拆单</el-button>

      <el-button v-if="operationList.includes('shipment:add')" @click="shipmentClick">去发货</el-button>
    </div>

    <el-dialog
      title="拆单"
      :visible.sync="splitOrderNewDialog"
      width="80%"
      :close-on-click-modal="false"
    >
      <splitOrder
        :projectId="projectId"
        :currentStageid="currentStageid"
        :order-id="chooseOrderId"
        @closeDialog="closeSplitOrderNewDialog"
        @doRefushSplitOrder="doRefushSplitOrder"
        :split-order-type="2"
      ></splitOrder>
    </el-dialog>

    <el-dialog
      title="去发货"
      :visible.sync="shipmentDialog"
      width="60%"
      :close-on-click-modal="false"
    >
      <div>
        <el-form ref="form" :model="form" label-width="180px">
          <el-form-item label="地址">
            <el-select
            v-model="form.address"
            placeholder="请选择地址"
            @change="selectchange2"
          >
            <el-option v-for="(item) in cangkulist" :key="item.id"  :label="item.sysValueName" :value="item.id"></el-option>
          </el-select>
          </el-form-item>
         
          <el-form-item label="预计到达时间">
            <!-- <el-input v-model="form.arrivalTime"></el-input> -->
            <el-date-picker
              v-model="form.arrivalTime"
              type="datetime"
              placeholder="选择预计到达时间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="发货形式">
            <el-select
              v-model="form.shipmentTypeCode"
              placeholder="请选择发货形式"
              @change="selectchange"
            >
              <el-option label="货拉拉" value="huolala"></el-option>
              <el-option label="快递" value="delivery"></el-option>
              <el-option label="其它" value="other"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="司机和车辆信息"
            v-if="selectactive !== '' && selectactive == 'huolala'"
          >
            <el-input v-model="form.driverCar"></el-input>
          </el-form-item>
          <el-form-item
            label="快递单号"
            v-if="selectactive !== '' && selectactive == 'delivery'"
          >
            <el-input v-model="form.shipmentNo"></el-input>
          </el-form-item>

          <!-- <el-form-item label="发货形势名称">
            <el-input v-model="form.shipmentTypeName"></el-input>
          </el-form-item> -->
          <el-form-item label="是否全部发货">
            <el-switch
              v-model="form.isAllShipment"
              :active-value="1"
              :inactive-value="2"
            ></el-switch>
          </el-form-item>
          <el-form-item label="体积">
            <el-input v-model="form.volume"></el-input>
          </el-form-item>
          <el-form-item label="重量">
            <el-input v-model="form.weight"></el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input type="textarea" v-model="form.remark"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="splitOrderNewDialog = false">取 消</el-button>
        <el-button type="primary" @click="splitOrderNewDialogVisibleConfirm"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import APIOrder from "@/api/apiOrder";
import qs from "qs";
import APISysLabel from "@/api/apiSysLabel";
import splitOrder from "@/views/order/pages/splitOrder/SplitOrder";
import API from "@/api/apidetail";
import FileDownloader from "@/components/utils/FileDownloader";
import APIdetail from "@/api/apidetail";
export default {
  name: "SignedProject",
  components: {
    splitOrder,
    FileDownloader,
  },
  props: {
    operationList: Array,
    isShow: Boolean,
    currentStageid: Number,
  },
  data() {
    return {
      splitOrderNewDialog: false,
      shipmentDialog: false,
      chooseOrderId: null,
      projectId: null,
      fileTypeList: [],
      selectactive: "",
      finalfile: { filePath: "", fileName: "" },
       // 添加发货形式映射关系
       shipmentTypeMap: {
        'huolala': '货拉拉',
        'delivery': '快递',
        'other': '其它'
      },
      form: {
        address: 440,
        driverCar: "",
        isAllShipment: 1,
        remark: "",
        shipmentNo: "",
        shipmentTypeCode: "",
        shipmentTypeName: "",
        arrivalTime: Date.now(),
        volume: "",
        weight: "",
      },
      cangkulist:[],
    };
  },
  methods: {
    splitOrderClick() {
      this.splitOrderNewDialog = true;
    },
    doRefushSplitOrder() {
      this.splitOrderNewDialog = false;
    },
    closeSplitOrderNewDialog() {
      this.splitOrderNewDialog = false;
    },
    shipmentClick() {
      this.shipmentDialog = true;
      this.form = {
        address:440,
        driverCar: "",
        isAllShipment: 1,
        remark: "",
        shipmentNo: "",
        shipmentTypeCode: "",
        shipmentTypeName: "",
        arrivalTime: Date.now(),
        volume: "",
        weight: "",
      };
    },
    onSubmit() {},
    splitOrderNewDialogVisibleConfirm() {
      let params = this.form;
      params.projectId = this.projectId;
      params.stageId = this.currentStageid;
      if (params) {
        API.shipmentcreate(params).then((res) => {
          if (res.key == 1000) {
            this.$message.success(res.message);
            this.shipmentDialog = false;
            this.$emit('get-stage');
          }
        });
      }
    },
    handleChange(val) {
      console.log(val);
    },
    //获取终版合同
    getFinalFile() {
      let params = {
        fileType: 5089,
        projectId: this.projectId,
      };
      APIdetail.getFinalFile(params).then((res) => {
        if (res.key == 1000) {
          this.finalfile = res.result.data;
        }
      });
    },

    selectchange(val) {
      this.selectactive = val;
      this.form.shipmentTypeName = this.shipmentTypeMap[val] || '';
    },
    selectchange2(val) {
    
    },
    getSysLabel() {
            this.$bus.$emit("show-loading", true);
            const params = {
                token: this.$store.state.token,
                sysLabelIds: '14',
            };
            APISysLabel.getSysLabelValueManageList(params).then((res) => {
                if (res.key === 1000) {
                this.cangkulist = res.result.data[14];
                }
                this.$bus.$emit("show-loading", false);
            });
        },
  },

  created() {
    let projectId = this.$ls.get("projectId");
    this.projectId = projectId;
    this.getFinalFile();
    this.getSysLabel();
  },
};
</script>

<style></style>
